/**
 * 
 */
package com.sip.comadapter.executor;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sip.comadapter.common.BaseExecutor;
import com.sip.comadapter.executor.common.Executor;
import com.sip.comserver.communication.CommunicationMessage;
import com.sip.dbadapter.dao.domain.ApiDefinition;
import com.sip.dbadapter.dao.domain.SystemInfo;
import com.sip.dbadapter.dao.interfaces.ApiDao;
import com.sip.dbadapter.dao.interfaces.FilteringDAO;
import com.sip.dbadapter.dao.utility.DaoLoadFactory;
import com.sip.dbadapter.domain.registry.DomainRegistry;

/**
 * @author da40188
 *
 */
public class GenericAPIFilteringExecutor extends BaseExecutor implements Executor {

	public CommunicationMessage execute(CommunicationMessage message) throws Exception {
		
		System.out.println("<<<<<<<<<<<<<<< GenericAPIFilteringExecutor >>>>>>>>>>>>>>>");
		
		Map<String, Object> domains = (Map<String, Object>) message.getObject();
		
		ApiDefinition apiDefinition = (ApiDefinition) domains.get(DomainRegistry.API_DEFINITION);
		SystemInfo systemInfo = (SystemInfo) domains.get(DomainRegistry.SYSTEM_INFO);

		FilteringDAO<Object> filteringDao = (FilteringDAO<Object>) DaoLoadFactory.getDao("FILTER");

		//List<ApiDefinition>  returnedApiDefinitions = filteringDao.searchAPI(apiDefinition, systemInfo);
		List<ApiDefinition>  returnedApiDefinitions = filteringDao.searchTest(apiDefinition, systemInfo);
		
		Map<String, Object> returnedDomains = new HashMap<String, Object>();
		
		for (ApiDefinition retApi : returnedApiDefinitions) {
		    System.out.println("---------------> "+ retApi.getName() + "----"+retApi.getPackageHierachy() + "---");
			returnedDomains.put(retApi.getName(), retApi);
		}
		message.setObject(returnedDomains);

		return message;
	}
	
	
	

}
